package com.lujieni.springbootflowable.listener;

import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

/**
 *  流程完成监听器
 *
 *  1. take事件只能适用于sequenceFlow
 *  2. ExecutionListener需要在流程定义中配置才能回调
 *  3. 执行监听器可以加载任何元素身上
 */
@Component
public class ProcessEndListener implements ExecutionListener {
    @Override
    public void notify(DelegateExecution execution) {
        System.out.println("=== 流程完成回调 ===");
        System.out.println("流程实例ID: " + execution.getProcessInstanceId());

        // 获取最终审批结果
        Boolean approved = (Boolean) execution.getVariable("approved");
        String applyUser = (String) execution.getVariable("applyUser");
        String title = (String) execution.getVariable("title");

        System.out.println("申请人: " + applyUser);
        System.out.println("申请标题: " + title);
        System.out.println("最终结果: " + (approved ? "通过" : "拒绝"));
    }
}
